<template>
  <div class="addsubject-container">
    <!-- 添加对话框 -->
    <el-dialog title="添加学科" :visible.sync="addDialogVisible" width="30%">
      <el-form
        :model="addForm"
        :rules="addFormRules"
        ref="addFormRef"
        label-width="100px"
      >
        <el-form-item label="学科名称" prop="subjectName">
          <el-input v-model="addForm.subjectName"></el-input>
        </el-form-item>
        <el-form-item label="是否显示" prop="isFrontDisplay">
          <el-switch
            v-model="addForm.isFrontDisplay"
            active-color="#13ce66"
            inactive-color="#ff4949"
            :active-value="1"
            :inactive-value="0"
          >
          </el-switch>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="addDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="addSubjectForm">确 定</el-button>
      </span>
    </el-dialog>
    <!-- /添加对话框 -->
  </div>
</template>

<script>
export default {
  name: 'SubjectAdd',
  props: {
    addDialogVisible: {
      type: Boolean,
      requred: true
    },
    addForm: {
      type: Object,
      requred: true
    },
    addFormRules: {
      type: Object,
      requred: true
    }
  },
  methods: {
    addSubjectForm() {
      this.$refs.addFormRef.validate(async valid => {
        //  console.log(valid);
        if (!valid) {
          return
        }
        // 发起请求
        // try {
        //   const { data } = await addSubjects(this.addForm)
        //   console.log(data, '------------------')
        //   this.$message.success('添加学科数据成功!')
        // } catch (err) {
        //   this.$message('添加学科数据失败!')
        // }
        this.$emit('add-subject')
      })
    }
  }
}
</script>

<style scoped lang="less"></style>
